home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.4 Applications 1997 August / SGI IRIX 6.4 Applications 1997 August.iso / dist / mmailp.idb / usr / lib / Zmail / samples / zscript / searchit.zsc.z / searchit.zsc
Encoding:
Text File  |  1997-01-22  |  2.0 KB  |  95 lines

  1. # Sample Z-Script functions: searchit, find-all
  2. #                    button: Find It
  3.  
  4. function searchit() {
  5. #%
  6. #   searchit [-c command] [-r] folder [pick-options] pattern
  7. #
  8. # Open the indicated folder (read-only if -r) and search it.  If the
  9. # pattern is found, leave the folder open.  Otherwise close it.  If
  10. # a command is specified, apply it to all the matching messages.
  11. #%
  12.     if $1 == -c
  13.     set _command="$2"
  14.     shift 2
  15.     else
  16.     set _command=msg_list
  17.     endif
  18.     if $1 == -r
  19.     set _open="open -r"
  20.     shift
  21.     else
  22.     set _open=open
  23.     endif
  24.     if $?savefolder
  25.     if $1 != $savefolder
  26.         $_open -N $1
  27.     else
  28.         folder -N $1
  29.     endif
  30.     if $status == -1
  31.         return 0
  32.     endif
  33.     else
  34.     $_open $1
  35.     endif
  36.     shift
  37.     if $# == 0
  38.     error ${0}: No pattern specified.
  39.     return -1
  40.     endif
  41.     pick $* | $_command
  42.     if $status == -1
  43.     return -1
  44.     endif
  45.     if X$output == X
  46.     close -N
  47.     endif
  48.     unset _open _command
  49.     return 0
  50. }
  51.  
  52. function find-all() {
  53. #%
  54. #   find-all [pick-options] pattern
  55. #
  56. # Search every file in $folder for the pattern.  Open all the folders
  57. # for which there is a match.  Mark all the matching messages in the
  58. # newly opened folders.  If there are matches in the current folder,
  59. # show the message summaries of (or select in GUI mode) the matches.
  60. #%
  61.     if $# == 0
  62.     error ${0}: No pattern specified.
  63.     return -1
  64.     endif
  65.     set savefolder=$thisfolder
  66.     ask 'WARNING:\n\
  67. This function updates and closes all folders that\n\
  68. do not contain messages matching the search pattern.\n\
  69. Proceed anyway?'
  70.     if $status != 0
  71.     return 0
  72.     endif
  73.     foreach _f (+*) 'searchit -c mark -r $_f $*'
  74.     if $status != 0
  75.     unset savefolder _f
  76.     return -1
  77.     else
  78.     unset savefolder _f
  79.     endif
  80.     if is_gui
  81.     # "folder -l" pops up Folders dialog in GUI mode, so we don't do it
  82.     :m | unmark                # Select 'em and unmark 'em
  83.     else
  84.     echo
  85.     echo Found matching messages in:
  86.     folder -l
  87.     echo
  88.     :m | unmark | from
  89.     if is_fullscreen
  90.         echo                # Leave an extra blank line
  91.     endif
  92.     endif
  93. }
  94. button -n "Find It" find-all
  95.